package com.apping.module;

import com.apping.module.R;
import com.apping.module.layout.MajorLayoutAtv;
import com.apping.module.button.MajorBtnAtv;
import com.apping.module.dialog.MajorDialogAtv;
import com.apping.module.edittext.MajorEditTextAtv;
import com.umeng.analytics.MobclickAgent;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MainActivity extends Activity {

	private SelectEvent m_selectEvent;
	private Class<?>    m_cls;
	private Intent		 m_intent;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		m_selectEvent = new SelectEvent(this);
		m_intent      = new Intent();
		
		initUI();
	}
	
	public void onResume() {
	    super.onResume();
	    MobclickAgent.onPageStart("SplashScreen"); //统计页面
	    MobclickAgent.onResume(this);          //统计时长
	}
	public void onPause() {
	    super.onPause();
	    MobclickAgent.onPageEnd("SplashScreen"); // 保证 onPageEnd 在onPause 之前调用,因为 onPause 中会保存信息 
	    MobclickAgent.onPause(this);
	}

	public void initUI()
	{
		Button majorBtnV  = (Button) findViewById(R.id.major_button);
		majorBtnV.setOnClickListener(m_selectEvent);
		
		Button layoutBtnV = (Button) findViewById(R.id.major_layout);
		layoutBtnV.setOnClickListener(m_selectEvent);
		
		Button editTextBtnV = (Button) findViewById(R.id.major_EditText);
		editTextBtnV.setOnClickListener(m_selectEvent);
		
		Button dialogBtnV = (Button) findViewById(R.id.major_Dialog);
		dialogBtnV.setOnClickListener(m_selectEvent);
	}
	
	public void NextAtv()
	{
		m_intent.setClass(getApplication(),m_cls);
		startActivity(m_intent);
		//this.finish();
	}
	
	public void SetNextAtv( Class<?> cls)
	{
		m_cls = cls;
	}
	

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {

		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.
		int id = item.getItemId();
		if (id == R.id.action_settings) {
			return true;
		}
		return super.onOptionsItemSelected(item);
	}
}


class SelectEvent implements OnClickListener{
	private MainActivity m_atv;
	public SelectEvent(MainActivity atv)
	{
		m_atv = atv;
	}
	
	@Override
	public void onClick(View v)
	{
		int id;
		id = v.getId();
		if (id == R.id.major_button){
			m_atv.SetNextAtv(MajorBtnAtv.class);
		}
		
		if (id == R.id.major_layout) {
			m_atv.SetNextAtv(MajorLayoutAtv.class);
		}
		
		if (id == R.id.major_EditText){
			m_atv.SetNextAtv(MajorEditTextAtv.class);
		}
		
		if (id == R.id.major_Dialog){
			m_atv.SetNextAtv(MajorDialogAtv.class);
		}
		
		m_atv.NextAtv();
	}
	
}

